{% extends 'IcsocUIBundle::page.html.twig' %}
{% from 'IcsocUIBundle:Macro:actions.html.twig' import create %}
{% from 'IcsocUIBundle:Macro:formValidator.html.twig' import jqvalidator %}
{% form_theme form _self %}
{% block stylesheet %}
    {{ parent() }}
    {% stylesheets
    '@gritter_css'
    filter='cssrewrite' filter='uglifycss'
    %}
    <link rel="stylesheet" href="{{ asset_url }}" />
    {% endstylesheets %}
{% endblock %}
{% block content %}
        <div class="col-xs-12 col-sm-12">
            {{ form_start(form, {'attr':{'id':'group_form'}}) }}
                {{ form_row(form.groupName) }}
                {{ create() }}
            {{ form_end(form) }}
        </div>
{% endblock %}
{% block footer %}
    {% javascripts
    '@jqvalidate_js'
    filter='uglifyjs'
    %}
    <script src="{{ asset_url }}"></script>
    {% endjavascripts %}
    <script>
        $(document).ready(function (){
            $('#group_form').validate({
            {{ jqvalidator() }}
                rules: {
                    'group_info_form[groupName]':{
                        required:true,
                        remote: {
                            url: '{{ path('icsoc_group_check') }}',
                            type: 'post',
                            dataType: 'json',
                            data: {
                                groupName: function(){
                                    return $('#group_info_form_groupName').val();
                                },
                                group_id: function(){
                                    {% if group_id is defined %}
                                        return '{{ group_id }}';
                                    {% endif %}
                                }
                            }
                        }
                    }
                },
                messages: {
                    'group_info_form[groupName]': {required:'{{ 'Business group name cannot be empty'|trans }}', remote:'{{ 'The business group already exists'|trans }}'}
                }
            })
        })

    </script>
{% endblock %}